package lab6.systemCustom;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

class SystemMain {

	@SuppressWarnings("unused")
	public static void main(String args[]) {
		// Verificarea numarului de parametri.
		if (args.length != 3) {
			System.err.println("Numar incorect de parametri");
			System.err.println("Usage: java SystemMain <StudentFile> <CourseFile> <LogFile>");
			System.exit(1);
		}
		String studentFileName = args[0];
		String courseFileName = args[1];
		String logFileName = args[2];

		// Verificarea existentei fisierelor.
		if (new File(studentFileName).exists() == false) {
			System.err.println("Could not find " + studentFileName);
			System.exit(1);
		}
		if (new File(courseFileName).exists() == false) {
			System.err.println("Could not find " + courseFileName);
			System.exit(1);
		}

		EventBus.initialize();

		// Crearea componentelor.
		try {
			DataBase db;
			db = new DataBase(studentFileName, courseFileName);

			ListAllStudentsHandler objCommandEventHandler1 = new ListAllStudentsHandler(db, EventBus.EV_LIST_ALL_STUDENTS, EventBus.EV_SHOW);
			ListAllCoursesHandler objCommandEventHandler2 = new ListAllCoursesHandler(db, EventBus.EV_LIST_ALL_COURSES, EventBus.EV_SHOW);
			ListStudentsRegisteredHandler objCommandEventHandler3 = new ListStudentsRegisteredHandler(db, EventBus.EV_LIST_STUDENTS_REGISTERED,
					EventBus.EV_SHOW);
			ListCoursesRegisteredHandler objCommandEventHandler4 = new ListCoursesRegisteredHandler(db, EventBus.EV_LIST_COURSES_REGISTERED, EventBus.EV_SHOW);
			ListCoursesCompletedHandler objCommandEventHandler5 = new ListCoursesCompletedHandler(db, EventBus.EV_LIST_COURSES_COMPLETED, EventBus.EV_SHOW);
			RegisterStudentHandler objCommandEventHandler6 = new RegisterStudentHandler(db, EventBus.EV_REGISTER_STUDENT,
					EventBus.EV_RESPONSE_TO_COURSE_CONFLICT_CHECK, EventBus.EV_SHOW);
			CourseConflictCheck courseConflictCheck = new CourseConflictCheck(db, EventBus.EV_CHECK_COURSE_CONFLICT,
					EventBus.EV_RESPONSE_TO_COURSE_CONFLICT_CHECK);
			ClientInput objClientInput = new ClientInput();
			ClientOutput objClientOutput = new ClientOutput();
			Logger logger = new Logger(logFileName);
			CourseOverdemandCheck objCourseOverdemandCheck = new CourseOverdemandCheck(db);
			TaxStudent objTaxStudent = new TaxStudent(db);

			objClientInput.start();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			System.exit(1);
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

}